<?php

namespace App\Services\Game;

use App\DTOS\Admin\UserMemberDTO;
use App\Models\Game\UserMember;


class UserMemberService
{
    /**
     * @param UserMemberDTO $userMemberDTO
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function paginate(UserMemberDTO $userMemberDTO){
        $model = UserMember::query();
        $username = $userMemberDTO->getUsername();
        $page = $userMemberDTO->getPage();
        $pageSize = $userMemberDTO->getLimit();
        $customerIds = $userMemberDTO->getCustomerIds();
        if ($username){
            $model->where('username','like',"%$username%");
        }
        if(!empty($customerIds)){
            $model->whereIn('yyOpenId',$customerIds);
        }
        return $model->paginate($pageSize,'*','page',$page);
    }

    /**
     * @param $id
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
     */
    public function getById($id)
    {
        return UserMember::query()->where('id',$id)->first();
    }

    /**
     * @param $ids
     * @param string[] $fields
     * @return array|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public function getByIds($ids,$fields = ['*'])
    {
        if (empty($ids)) return [];
        return UserMember::query()->whereIn('id',$ids)->select($fields)->get();
    }

}
